package deadlock

import "fmt"
import "dumpwave"
func pc(
	//pc_command		chan int32,
	instruction_address	chan uint32,
	decodePC		chan DEPC,
	aluPc			chan uint32) {

//     var(
// 		vPC,
// 		vCoreInstAddr,
// 		vDecodeInstAddr,
// 		vMemInstAddr int32
// 	)
	var vPC uint32

	fmt.Println("[PC ] Starting Program Counter")
	vPC = 0
	fmt.Println("[PC ] Starting PC=", vPC)
	instruction_address <- vPC

	for{
		select{
			case depc :=<- decodePC :
				vCommand := depc.PC_COMMAND
				fmt.Println("[PC ] pc_command received", vCommand)
				switch vCommand {
						case PC_NEXT:
							fmt.Println("[PC ] PC_NEXT received")
							vPC += INSTRUCTION_SIZE

						case PC_IMMEDIATE_JUMP:
							vPC = (vPC &  0xF0000000) | depc.PC_IMMEDIATE<<2
				}
			case target_offset:=<- aluPc:
				vPC += target_offset
			
		}
		instruction_address <- vPC
		fmt.Println("[PC ] vPC sent: ", vPC)
// 		vCoreInstAddr = vDecodeInstAddr
// 		vDecodeInstAddr = vMemInstAddr
// 		vMemInstAddr = vPC
	}
}